﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO;

namespace bxml.betterxml.parsers
{

    /**
     * This uses the an adapter to translate from sax events to BetterXmlContentHandler events.
     * 
     * @see BetterXmlContentHandler 
     * @see Sax2BetterXmlContentHandlerAdapter
     */
    public class XmlParser : BetterXmlParser
    {
        //private XmlReader xmlReader;
        private BetterXmlContentHandler handler;

        /**
         * Create a new xml parser.  
         * @throws BetterXmlException
         */
        public XmlParser()
        {
            //try {
            //    xmlReader = XMLReaderFactory.createXMLReader();
            //    xmlReader.setFeature("http://xml.org/sax/features/namespaces", true);
            //    xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
            //} catch (SAXException e) {
            //    throw new BetterXmlException(e);
            //} 
        }

        public void parse(StreamReader reader)
        {
            //ContentHandler saxHandler = new Sax2BetterXmlContentHandlerAdapter(handler);
            //xmlReader.setContentHandler(saxHandler);

            //try {
            //    xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", saxHandler);
            //    xmlReader.parse(new InputSource(reader));
            //} catch (Exception e) {
            //    throw new BetterXmlException(e);
            //}

        }

        public BetterXmlContentHandler getContentHandler()
        {
            return handler;
        }

        public BetterXmlParser setContentHandler(BetterXmlContentHandler handler)
        {
            this.handler = handler;
            return this;
        }
    }
}
